package com.iap.app.util
{
	import com.iap.app.util.logger.Log;
	
	import flash.utils.describeType;

	public class Utils
	{
		public static function random(min:Number, max:Number):Number
		{
			return min + Math.random() * (max - min);
		}
		
		public static function stringToDate(txt:String):Date
		{
			var date:Date = null;
			try {
				var year:Number = txt.split("-")[0];
				var month:Number = txt.split("-")[1];
				var day:Number = txt.split("-")[2].split("T")[0];
				var hours:Number = 0;
				var minutes:Number = 0;
				var seconds:Number = 0;
				if(txt.length>10)
				{
					hours = txt.split("T")[1].split(":")[0];
					minutes = txt.split("T")[1].split(":")[1];
					seconds = txt.split("T")[1].split(":")[2];
				}
				date = new Date(year,(month-1),day, hours, minutes, seconds);
			} catch(err:Error){
				Log.Error("Utils.stringToDate Error > " + err.message +" ("+txt+")");
				throw new Error("Utils.stringToDate Error > " + err); 
			}
			return date;
		}
		
		public static function shuffleVectorSort( a:Object, b:Object ):int
		{
			return Math.floor( Math.random() * 3 - 1 );
		}
		
		private static function itemExist(sourceXMLAccessor:XMLList, itemName:String):Boolean
		{
			return sourceXMLAccessor.(@name==itemName).length()>0;
		}

		public static function mergeXMLlists(list1:XMLList, list2:XMLList):XMLList
		{
			var items:XML = <xml/>;
			
			var item:XML;
			for each (item in list1)
			items.appendChild(item);
			
			for each (item in list2)
			items.appendChild(item);
			
			return items.children();
		}
	}
}